#ifndef IC_HANDLER_H
#define IC_HANDLER_H

#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>

#include "../event_handler.h"
#include "../i_socket.h"
#include "../listener.h"
#include "../temperature.h"
#include "../model/dom.h"
#include "../configurator.h"
#include "../singletone.h"

namespace handler {
	class ic_handler;
}

namespace handler {
	class ic_handler : public network::event_handler, 
			   public network::listener {
	public:
		ic_handler(boost::shared_ptr<network::i_socket> ic, 
			   boost::shared_ptr<network::i_socket> web)
		: _ic(ic), _web(web) {}
		virtual ~ic_handler() {}

		virtual network::event_type get_type() const
		{
			return network::RECEIVE;
		}
		virtual boost::shared_ptr<const network::i_socket>
			get_socket() const {return _ic;}
		virtual void handle_event(boost::shared_ptr<network::event> n);
		/**
		 * get notified if the receiver gets disconnect...
		 */
		virtual void notify(const network::notifier *n);

		static boost::shared_ptr<handler::ic_handler> create(
			boost::shared_ptr<network::i_socket> ic,
			boost::shared_ptr<network::i_socket> web)
		{
			boost::shared_ptr<handler::ic_handler> ptr(
				new handler::ic_handler(ic, web));
			ptr->_this = ptr;
			return ptr;
		}
	private:
		void do_temp(boost::shared_ptr<model::dom> node);

		boost::shared_ptr<network::i_socket> _ic;
		boost::shared_ptr<network::i_socket> _web;
		boost::weak_ptr<handler::ic_handler> _this;
	};
}

#endif
